<template>
  <div>
<!--    <a-dropdown :disabled="selectedRowKeys.length<= 1">-->
    <a-dropdown >
      <a-button style="margin-left: 8px;margin-bottom: 8px" type='primary' @click.native='merge'> 类别设置 </a-button>
    </a-dropdown>
    <a-table
      ref='table'
      size='middle'
      bordered
      :rowKey="record => record.id"
      childrenColumnName='childrenColumnName'
      :columns='columns'
      :dataSource='dataSource'
      :loading='loading'
      :pagination="false"
    >
    </a-table>
    <category-statistics-merge-modal ref='mergeModal' @update='loadDate' ></category-statistics-merge-modal>
  </div>
</template>

<script>
import CategoryStatisticsMergeModal
  from '@views/data-governance/smart-reports/epidemic-weekly/components/CategoryStatisticsMergeModal'
import ReportsEpidemicWeeklyService from '@/myService/ReportsEpidemicWeeklyService'

const temp={};
const mergeCells=(text,array,columns)=>{
  let i=0;
  if(text != temp[columns]){
    temp[columns]=text;
    array.forEach((item)=>{
      if(item.mergeContent===temp[columns]){
        i=i+1;
      }
    })
  }
  return i;
}
export default {
  name: 'Step3',
  components:{
    CategoryStatisticsMergeModal,
  },
  data() {
    return {
      loading:false,
      periodId:'',
      dataSource: [],
      columns: [
        {
          title: '类别',
          align: 'center',
          width: 200,
          dataIndex: 'mergeContent',
          customRender: (text, row, index) => {
            if(row.mergeId !==null){
              const obj = {
                children: row.mergeContent+"("+row.mergeNum+"件)",
                attrs:{}
              };
              obj.attrs.rowSpan=mergeCells(row.mergeContent,this.dataSource,'mergeContent')
              return obj;
            }
            else {
              const obj = {
                children: <span>暂无</span>,
                attrs:{}
              };
              return obj
            }
          },
        },
        {
          title: '内容',
          customRender: (text, row, index) => <span>{row.name}({row.content})</span>,
        },
        {
          title: '工单总数',
          align: 'center',
          dataIndex: 'summation',
          width:80,
          ellipsis: true,
        },
        {
          title: '占比（%）',
          align: 'center',
          dataIndex: 'proportion',
          width:150,
          ellipsis: true,

        }
      ],
    }
  },
  created() {

  },
  methods:{
    async begin(periodId){
      this.periodId=periodId
      this.loading=true;
      this.loadDate();
      this.loading=false;
    },
    loadDate(){
      this.dataSource=[]
      ReportsEpidemicWeeklyService.getStatisticsCategoryMerge(this.periodId).then(res=>{
        if (res.success) {
          this.dataSource = res.result.records || res.result
          console.log(this.dataSource)
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    merge(){
      this.$refs.mergeModal.open(this.periodId)
    },
  }
}
</script>

<style scoped>

</style>